package com.dgut.coal.controller;

import com.dgut.coal.entity.Info;
import com.dgut.coal.service.InfoService;
import com.dgut.coal.service.PurchaseService;
import com.dgut.coal.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;

import java.util.List;
import java.util.Map;

/**
 * @Author: Yang
 * @Description:
 * @Date: Created in 11:19 2019/10/7
 * @Modifued BY:
 */

@Controller
public class CommonController {

    @Autowired
    InfoService is;

    @Autowired
    PurchaseService ps;

    @Autowired
    UserService us;

    /**
     * 前往welcome界面,统计公告数,统计咨询数等
     */
    @RequestMapping("/welcome")
    public String welcome(Map<String, Object> map){
        int infoCount = is.count();
        int purchaseCount = ps.count();
        int infoAudit = is.auditCount();
        int purchaseAudit = ps.auditCount();
        int userCount = us.userCount();
        int roleCount = us.roleCount();
        List<Info> lastest = is.lastest();
        map.put("infoCount",infoCount);
        map.put("purchaseCount",purchaseCount);
        map.put("infoAudit",infoAudit);
        map.put("userCount",userCount);
        map.put("roleCount",roleCount);
        map.put("purchaseAudit",purchaseAudit);
        map.put("lastest",lastest);
        return "welcome";
    }

    /**
     * 进入后台之后在“我的桌面”看最新的公告
     * @param notify_id
     * @param map
     * @return
     */
    @RequestMapping("/annDetail")
    public String annDetail(Integer notify_id,Map<String, Object> map){
        Info ainfo = is.ainfo(notify_id);
        map.put("ainfo",ainfo);
        return "ann-detail";
    }


    /**
     * 首页进入资讯的详情方法
     * @param notify_id
     * @param map
     * @return
     */
    @RequestMapping("/mainDetail")
    public String mainDetail(Integer notify_id,Map<String, Object> map){
        Info ainfo = is.ainfo(notify_id);
        map.put("ainfo",ainfo);
        return "annDetail";
    }

    @RequestMapping("/error")
    public String error(){
        return "error";
    }

    /*@RequestMapping("/echarts")
    public String echarts(){

        return "echarts";
    }
*/
}
